package defiant.common.web;

import java.util.Map;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;

import defiant.common.tools.ResourceUtil;

/**
 * Servlet implementation class LoginServlet
 */
public abstract class DefiantServlet extends HttpServlet {

    /**
	 * 
	 */
	private static final long serialVersionUID = 605306517186352769L;

	/**
     * The context key for the HTTP request object.
     */
    protected static final String REQUEST = "request";

    /**
     * The context key for the HTTP response object.
     */
    protected static final String RESPONSE = "response";
	
    
	protected VelocityContext getVelocityContext(HttpServletRequest request, HttpServletResponse response) {
		VelocityContext ctx = new VelocityContext();
		ctx.put(REQUEST, request);
		ctx.put(RESPONSE, response);
		
		Map<String, String> map = ResourceUtil.loadMap("resources.ApplicationResources");
		ctx.put("resource", map);
		
		return ctx;
	}
	

//	/**
//	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
//	 */
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		System.out.println("login servlet --");
//		
//		try {
//			Template t = Velocity.getTemplate("test/login.html");
//			
//			VelocityContext ctx = getVelocityContext(request, response);
//			ctx.put("title", "Velocity Login Page");
//			ctx.put("name", "Roy");
//			ctx.put("velocity", "Velocity");
//			
//			
//			request.setAttribute("test", "tesglsfjlsnflsndlsdfnklsdf");
////			ctx.put("map", request.getSession().)
//			
//			PrintWriter writer = response.getWriter();
//			t.merge(ctx, writer);
//		} catch (ResourceNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (ParseErrorException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
//
//	/**
//	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
//	 */
//	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//	}

}
